package net.qunzhi.modules.cms.service.impl;

import net.qunzhi.modules.cms.query.AlarmRecordRecordQuery;
import org.springframework.stereotype.Service;
import net.qunzhi.common.utils.BaseQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.qunzhi.common.utils.PageUtils;
import net.qunzhi.common.utils.Query;

import net.qunzhi.modules.cms.dao.TbAlarmRecordDao;
import net.qunzhi.modules.cms.entity.TbAlarmRecordEntity;
import net.qunzhi.modules.cms.service.TbAlarmRecordService;


@Service("tbAlarmRecordService")
public class TbAlarmRecordServiceImpl extends ServiceImpl<TbAlarmRecordDao, TbAlarmRecordEntity> implements TbAlarmRecordService {

    @Override
    public PageUtils queryPage(AlarmRecordRecordQuery query) {
        IPage<TbAlarmRecordEntity> page = this.page(
                new Query<TbAlarmRecordEntity>().getPage(query),
                new QueryWrapper<TbAlarmRecordEntity>()
                        .ge(null!=query.getStartDate(),"date(create_time)",query.getStartDate())
                        .le(null!=query.getEndDate(),"date(create_time)",query.getEndDate())
                        .orderByDesc("create_time")
        );

        return new PageUtils(page);
    }

    @Override
    public TbAlarmRecordEntity getInfoById(Integer id, long userId) {

        return this.baseMapper.getInfoById(id, userId);
    }

}